const propertyMap = new Map();
const observer = new ResizeObserver(entries => {
    for (let i = 0, len = entries.length; i < len; i++) {
        const el = entries[i].target;
        const height = el.getBoundingClientRect().height - 5;
        if (el.data) {
            el.data.value = height;
        }
        el.style.setProperty(propertyMap.get(el), height + 'px');
    }
});

/**
 * 指令
 * 使用方法：v-ref-height="varName"
 * @param varName string
 */
const RefHeight = {
    inserted(el, binding) {
        observer.observe(el);
        if (typeof binding.value === 'string') {
            propertyMap.set(el, '--' + (binding.value || 'ref-height'));
        } else {
            el.data = binding.value;
            propertyMap.set(el, '--' + 'ref-height');
        }
    },
    unbind(el) {
        observer.unobserve(el);
        propertyMap.delete(el);
    }
};
export default function installRefHeight(Vue) {
    Vue.directive('ref-height', RefHeight);
}
